﻿using Engine.Sgml.Validation;
using System;
using Engine.Sgml.Schema;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Engine.Sgml.Test.Fixtures;

namespace Engine.Sgml.Test {
    /// <summary>
    ///This is a test class for ModelGroupsRelocatorTest and is intended
    ///to contain all ModelGroupsRelocatorTest Unit Tests
    ///</summary>
    [TestClass]
    public class ModelGroupsRelocatorTest {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
                }
            set {
                testContextInstance = value;
                }
            }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Join
        ///</summary>
        [TestMethod]
        public void JoinTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement startElement = second.StartElement;
            SElement endElement = ModelGroupsMatch.GetEndElement(first);
            ModelGroupsMatch.Join(first, second);
            Debug.Assert(endElement.NextNode() == startElement);
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        [TestMethod]
        public void JoinWithRepetitiveTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement startElement = second.StartElement;
            SElement endElement = ModelGroupsMatch.GetEndElement(first);
            ModelGroupsMatch.Join(first.RepetitiveMatches[0], second);
            Debug.Assert(endElement.NextNode() == startElement);
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        /// <summary>
        ///A test for JoinAfterSelf
        ///</summary>
        [TestMethod]
        public void JoinAfterSelfTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement firstElement = second.StartElement;
            ModelGroupsMatch.JoinAfter(first, second);
            Debug.Assert(firstElement == first.EndElement.NextNode());
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        [TestMethod]
        public void JoinWithRepetitiveAfterSelfTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement firstElement = second.StartElement;
            SElement endElement = first.RepetitiveMatches[0].EndElement;
            ModelGroupsMatch.JoinAfter(first.RepetitiveMatches[0], second);
            Debug.Assert(firstElement == endElement.NextNode());
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        /// <summary>
        ///A test for JoinBeforeSelf
        ///</summary>
        [TestMethod]
        public void JoinBeforeSelfTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement endElement = ModelGroupsMatch.GetEndElement(second);
            ModelGroupsMatch.JoinBefore(first, second);
            Debug.Assert(endElement.NextNode() == first.StartElement);
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        [TestMethod]
        public void JoinWithRepetitiveBeforeSelfTest() {
            ModelGroupsMatch first = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch second = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out first, out second);
            SElement endElement = ModelGroupsMatch.GetEndElement(second);
            SElement startElement = first.RepetitiveMatches[0].StartElement;
            ModelGroupsMatch.JoinBefore(first.RepetitiveMatches[0], second);
            Debug.Assert(endElement.NextNode() == startElement);
            Debug.Assert(MatchTestUtility.Verify(first.Root), "A bounds of the specified match object are inconsistent.");
            }

        /// <summary>
        ///A test for Relocate
        ///</summary>
        [TestMethod]
        public void RelocateTest() {
            ModelGroupsMatch match = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatch target = null; // TODO: Initialize to an appropriate value
            ModelGroupsMatchBuilder.BuildMatchObjects(out match, out target);
            //target.Clear();
            target.Reset(match.Model, match.Ancestor);
            SElement startElement = match.StartElement;
            SElement endElement = match.EndElement;
            ModelGroupsMatch.Relocate(match, target);
            Debug.Assert(startElement == target.StartElement);
            Debug.Assert(endElement == target.EndElement);
            }
        }
    }
